/**
 * @summary 用户请求模块
 */

import req from '@/utils/request';
import * as URL from '@/constants/api';

// 关注
export function follow(id) {
  return req({
    url: URL.FOLLOW,
    method: 'POST',
    data: {
      target: id,
    }
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message));
}

// 登录
export function login(params) {
  return req({
    url: URL.LOGIN,
    method: 'POST',
    data: params,
  })
    .then(res => {
      // 记住token
      localStorage.setItem('TOKEN', `Bearer ${ res.data.data.token }`);
      return res.data.message;
    })
    .catch(err => Promise.reject(err.response.data.message));
}

// 用户自己的信息
export function getUserProfile() {
  return req({
    url: URL.USER,
  })
    .then(res => res.data.data)
    .catch(err => ({}));
}
